package Controller;

import Pojo.RoomNumber;
import Service.impl.RoomNumberServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class RoomNumQueryByRoomIdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        try {
            String roomIdGet = request.getParameter("roomId");
            RoomNumberServiceImpl roomNumberService=new RoomNumberServiceImpl();
            List<RoomNumber> roomNumberList=roomNumberService.RoomNumQueryByRoomId(Integer.parseInt(roomIdGet));
            String s= JSON.toJSONString(roomNumberList);
            response.getWriter().print(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
